'''
Created on May 27, 2011

@author: Amit
'''
import pickle

class Person:
    name = None
    age = 0
    
        
    def print_to_screen(self):
        print( ' my name is : ' + self.name )

def write_file( filename, text ):
    f = open( filename, 'w')
    f.write(text)
    f.close()
    
def read_file( filename ):
    f = open( filename, 'r')
    val =  f.readlines()
    f.close()
    return val


def write_person_to_file( filename, person ):
    f = open(filename, 'w')
    v = f.write
    print(v)
    pickle.dump( person, open(filename,'wb') )
    f.close()
    
def read_person_from_file( filename ):
    print("writing person to file")
    print( pickle.load(open(filename,'rb') ) )


#def print_pickle():
    favorite_color = { "lion": "yellow", "kitty": "red" }
    pickle.dump( favorite_color, open( "save.p", "wb" ) )

def read_prickle():
    return pickle.load( open("save.p","rb") )

    
# write_file("log.txt", "i am writing to file from function")    
#print (read_file("log.txt")) 

print("start")
p = Person()
p.name = 'guy'
p.age = 29
#write_person_to_file("person.txt", p)
read_person_from_file( "person.txt" )
#print("end")
#print_pickle()
#print(read_prickle())





   
 
